/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
  ListNode* getKthFromEnd(ListNode* head, int k) {

//    ListNode *dummyHead = new ListNode(-1, head);
    ListNode *fast = head;
    ListNode *slow = head;

    while(k - 1 > 0 && fast != nullptr){
      fast = fast->next;
      --k;
    }

    while(fast->next != nullptr){
      fast = fast->next;
      slow = slow->next;
    }

    return slow;

  }
};